package controllers

import (
	//"bluebell/logic"

	"go.uber.org/zap"
	"lottery/web/blue/bluebell/logic"
	"lottery/web/blue/bluebell/models"

	//"bluebell/logic"
	//"bluebell/models"
	"fmt"

	//"go.uber.org/zap"

	"github.com/gin-gonic/gin"
)

func PostVoteController(c *gin.Context) {
	// 1. 参数校验
	p := new(models.ParamsVoteData)
	if errMsg := validatorParams(c, p); errMsg != "" {
		fmt.Println(p)
		ResponseErrorWithMsg(c, CodeInvalidParam, errMsg)
		return
	}
	// 2. 逻辑处理
	// 首先获取当前登录的用户
	userID, err := GetCurrentUserID(c)
	if err != nil {
		ResponseError(c, CodeNeedLogin)
		return
	}
	if err := logic.VoteForPost(userID, p); err != nil {
		// 打印错误日志
		zap.L().Error("logic.VoteForPost() failed", zap.Error(err))
		// 返回错误结果
		ResponseError(c, CodeServerBusy)
		return
	}
	// 3. 成功返回
	ResponseSuccess(c, nil)
}
